<template>
  <div>
    <dv-full-screen-container>
      <div class="dashboard">
        <div class="header-box">
          <div class="header">
            <div class="quit-info">
              <div class="quit" @click="handleExit">退出</div>
            </div>
            <!-- <div class="title">
            <img src="./img/titleCockpit.png" alt="" />
          </div> -->
            <div class="info">
              <div class="info-date">
                {{ today.toLocaleString().replace(/\//g, "-") }} 星期{{
                  days[today.getUTCDay()]
                }}
              </div>
              <img
                src="./img/q1.png"
                alt=""
                @click="fullscreenToggler"
                style="
                  width: 30px;
                  height: 30px;
                  margin-right: 20px;
                  cursor: pointer;
                "
              />
            </div>
          </div>
          <div class="head-selection">
            <div class="date-picker-box">
              <el-date-picker
                class="echarts-head-date"
                size="medium"
                v-model="dateRange"
                type="daterange"
                value-format="yyyy-MM-dd"
                format="yyyy年MM月dd日"
                @change="handleEchartDateChange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="background-color: rgba(0, 17, 152, 0); width: 350px"
              >
              </el-date-picker>
            </div>
            <div style="width: 15%">
              <yjn ref="yjn" @yjnChange="yjnChange"></yjn>
            </div>
            <!-- <el-select
            size="medium"
            v-model="queryParams.dataType"
            placeholder="请选择维度"
            @change="changeDataType"
          >
            <el-option
              v-for="item in Dimension"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select> -->
            <div class="dimension-box">
              <div
                :class="queryParams.dataType === 0 ? 'bg' : ''"
                @click="changeDataType(0)"
                class="dimension-box-item"
              >
                <img src="./img/w.png" />
                <span>物料维度</span>
              </div>
              <div
                :class="queryParams.dataType === 1 ? 'bg' : ''"
                @click="changeDataType(1)"
                class="dimension-box-item"
              >
                <img src="./img/k.png" />
                <span>供应商维度</span>
              </div>
            </div>
            <el-select
              style="width: 15%"
              size="medium"
              filterable
              multiple
              :collapse-tags="true"
              v-model="queryParams.divisionId"
              placeholder="至少选择一个事业部"
              @change="changedivision"

            >
              <el-option
                v-for="item in deptList"
                :key="item.divisionId"
                :label="item.divisionName"
                :value="item.divisionId"
              >
              </el-option>
            </el-select>
            <el-select
              style="width: 13%"
              size="medium"
              v-model="queryParams.baseId"
              filterable
              multiple
              :collapse-tags="true"
              placeholder="至少选择一个基地"
              @change="changeBase"
            >
              <el-option
                v-for="item in factoryList"
                :key="item.baseId"
                :label="item.baseName"
                :value="item.baseId"
              >
              </el-option>
            </el-select>
            <el-select
              style="width: 8%"
              size="medium"
              v-model="queryParams.notes"
              filterable
              placeholder="请选择"
              @change="changeABC"
            >
              <el-option
                v-for="item in noteList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
            <el-select
              style="width: 6%"
              size="medium"
              v-model="queryParams.sort"
              placeholder="正序/倒序"
              @change="changeSort"
            >
              <el-option
                v-for="item in sortList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="body" ref="body">
          <div class="charts-item-box" style="">
            <div class="charts-item-box-item">
              <div class="charts-item-box-title">来 料 批 合 格 率</div>
              <div class="charts-item-box-chart-box">
                <div class="charts-item-box-chart br-right-none">
                  <!-- <div ref="echart1" style="width: 100%; height: 100%"></div> -->
                  <dc-progress :list="divisionRatioList" />
                </div>
                <div class="charts-item-box-chart br-right-none">
                  <div ref="echart4" style="width: 100%; height: 100%"></div>
                </div>
                <div class="charts-item-box-chart bg">
                  <div ref="echart7" style="width: 100%; height: 100%"></div>
                </div>
              </div>
            </div>
            <div class="charts-item-box-item">
              <div class="charts-item-box-title">来 料 批 检 验 完 成 率</div>
              <div class="charts-item-box-chart-box">
                <div class="charts-item-box-chart br-right-none">
                  <div ref="echart2" style="width: 100%; height: 100%"></div>
                </div>
                <div class="charts-item-box-chart br-right-none">
                  <div ref="echart5" style="width: 100%; height: 100%"></div>
                </div>
                <div class="charts-item-box-chart bg">
                  <div ref="echart8" style="width: 100%; height: 100%"></div>
                </div>
              </div>
            </div>
            <div class="charts-item-box-item">
              <div class="charts-item-box-title">不 合 格 处 理 完 成 率</div>
              <div class="charts-item-box-chart-box">
                <div class="charts-item-box-chart br-right-none">
                  <!-- <div ref="echart3" style="width: 100%; height: 100%"></div> -->
                  <echart3 :list="echart3List" />
                </div>
                <div class="charts-item-box-chart br-right-none">
                  <div ref="echart6" style="width: 100%; height: 100%"></div>
                </div>
                <div class="charts-item-box-chart bg">
                  <div ref="echart9" style="width: 100%; height: 100%"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </dv-full-screen-container>
    <deepEchartBarVue :visible.sync="isShow"></deepEchartBarVue>
    <deepEchartBar2Vue :visible.sync="isShow2"></deepEchartBar2Vue>
    <div id="menus" style="display: none">
      <ul>
        <!--右键弹出菜单-->
        <li id="menu_1" @click="godetail" v-if="!isShow">
          <span>明细</span>
        </li>
        <li id="menu_1" @click="getinspectionJumpMateriallocal">
          <span>图表</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import EchartColumn from "./echartColumn.vue";
import { divisionList } from "@/api/masterdata/division";
import { listALLFactory, listBaseAPI } from "@/api/basic/factory";
import {
  divisionAndBaseList,
  inspectionOKRatio,
} from "@/api/inspectionManagement/inspectionManagement";
import mixins from "./mixins";
import moment from "moment";
import deepEchartBarVue from "./deepEchartBar.vue";
import deepEchartBar2Vue from "./deepEchartBar2.vue";
import yjn from "./yjn.vue";
import progress from "./progress.vue";
import echart3 from "./echart3.vue";

const startTime = moment().startOf("month").format("YYYY-MM-DD");
const endTime = moment().endOf("month").format("YYYY-MM-DD");
export default {
  name: "dashboard",
  // dicts: ['AUDIT_TYPE','NYIQC_NCR_DECISION'],
  components: {
    EchartColumn,
    deepEchartBarVue,
    deepEchartBar2Vue,
    yjn,
    "dc-progress": progress,
    echart3
  },
  mixins: [mixins],
  data() {
    return {
      today: new Date(),
      days: ["日", "一", "二", "三", "四", "五", "六"],
      deptList: null,
      factoryList: null,
      bodyWidth: 0,
      bodyHeight: 0,
      clearable: false,
      queryParams: {
        notes: 0,
        qualified: 1,
        dimension: 0,
        sort: 1,
        baseId: [],
        divisionId: [],
        dataType: 0,
      },
      title: [
        { name: "来料批合格率" },
        { name: "来料不合格品流程完成率" },
        { name: "来料检验完成率" },
      ],
      Dimension: [
        { id: 0, name: "物料维度" },
        { id: 1, name: "供应商维度" },
      ],
      Qualified: [
        { id: 1, name: "合格" },
        { id: 0, name: "不合格" },
      ],
      sortList: [
        { id: 0, name: "正序" },
        { id: 1, name: "倒序" },
      ],
      noteList: [
        { id: 0, name: "A/B/C" },
        { id: 1, name: "主材/辅材" },
      ],
      params: null,
      isShow: false,
      isShow2: false,
      date: { dateType: "4", time: "2023" },
      dateRange: [],
      startTime: "",
      endTime: "",
    };
  },
  computed: {
    queryParams2() {
      return JSON.parse(JSON.stringify(this.queryParams));
    },
  },
  watch: {
    queryParams2: {
      handler(newVal, oldVal) {
        console.log(newVal, "入参发生变化！");
      },
      deep: true,
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.domInit();
      this.initPage();
    });
  },
  methods: {
    isFullscreen() {
      return (
        document.fullscreenElement ||
        document.webkitFullscreenElement ||
        document.mozFullScreenElement ||
        document.msFullscreenElement
      );
    },
    exitFullscreen() {
      if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
      } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
      } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
      }
    },
    requestFullScreen(element) {
      if (!this.isFullscreen()) {
        // 检查是否已全屏，如果不是则进入全屏模式
        var requestMethod =
          element.requestFullScreen ||
          element.webkitRequestFullScreen ||
          element.mozRequestFullScreen ||
          element.msRequestFullScreen;
        if (requestMethod) {
          // 如果浏览器支持全屏API
          requestMethod.call(element);
        } else if (typeof window.ActiveXObject !== "undefined") {
          // 对于IE浏览器，可以使用ActiveXObject
          var wscript = new ActiveXObject("WScript.Shell");
          if (wscript !== null) {
            wscript.SendKeys("{F11}");
          }
        }
      } else {
        // 如果已全屏则退出全屏模式
        this.exitFullscreen();
      }
    },
    fullscreenToggler() {
      const elem = document.body; // 让整个body全屏
      this.requestFullScreen(elem);
    },
    yjnChange(date) {
      this.date = date;
      this.startTime = "";
      this.endTime = "";
      this.dateRange = [];
      this.initPage(true);
    },
    handleEchartDateChange(date) {
      this.dateRange = date;
      this.startTime = date[0];
      this.endTime = date[1];
      this.date.time = "";
      this.date.dateType = "";
      // this.queryParams.dataType = "";
      this.$refs.yjn.clear();
      this.initPage(true);
    },
    changeDataType(dataType) {
      // this.queryParams.divisionId = [this.deptList[0].divisionId];
      // this.queryParams.baseId = [this.factoryList[0].baseId];
      this.queryParams.notes = 0;
      this.queryParams.dataType = dataType;
      console.log(this.queryParams.divisionId, this.queryParams.baseId);
      this.getinspectionDivisionBaseRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      //
      this.getinspectionBaseMaterialRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          baseIds: this.queryParams.baseId.join(),
          materialDataType: this.queryParams.notes,
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );

      this.getinspectionDivisionBaseMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionMaterialMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );

      this.getbaseInsFinishRateByExtra(
        {
          divisionId: this.queryParams.divisionId,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getsupplierInsFinishRateByExtra(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
    },
    changeSort() {
      this.initPage(true);
      // this.getinspectionDivisionBaseRatio({
      //   divisionIds: this.queryParams.divisionId.join(),
      //   dataType: this.queryParams.dataType,
      //   sort: this.queryParams.sort,
      // },this.queryParams.dataType);
      // this.getinspectionBaseMaterialRatio({
      //   divisionIds: this.queryParams.divisionId.join(),
      //   baseIds: this.queryParams.baseId.join(),
      //   materialDataType: this.queryParams.notes,
      //   dataType: this.queryParams.dataType,
      //   sort: this.queryParams.sort,
      // },this.queryParams.dataType)
    },
    getinspectionJumpMateriallocal() {
      
      if (this.isShow) {
        this.isShow2 = true;
        let materialCode = null;
        if (this.currentDeepEchart == 7.1) {
          for (const iterator of this.materialRatioList7_2
            .materialRatioList7_2) {
            if (
              iterator.materialName == this.deep2Params.name
              // &&
              // Number(iterator.ratio) * 100 == this.deep2Params.data
            ) {
              this.deep2Params.materialCode = iterator.materialCode;
            }
          }
          this.getinspectionJumpMaterialSupplierlocal();
          return;
        } else if (this.currentDeepEchart == 8.1) {
          console.log(
            this.materialRatioList8_2,
            this.deep2Params,
            "第八个二次下钻"
          );
          for (const iterator of this.materialRatioList8_2
            .materialRatioList8_2) {
            if (
              iterator.materialName == this.deep2Params.name
              // &&
              // Number(iterator.ratio) * 100 == this.deep2Params.data
            ) {
              this.deep2Params.materialCode = iterator.materialCode;
            }
          }
          this.getinspectionMaterialMrbRatioDeep2local();
        } else if (this.currentDeepEchart == 9.1) {
          console.log(
            this.materialRatioList9_2,
            this.deep2Params,
            "第八个二次下钻"
          );
          for (const iterator of this.materialRatioList9_2) {
            if (
              iterator.materialName == this.deep2Params.name
              // &&
              // Number(iterator.ratio) * 100 == this.deep2Params.data
            ) {
              this.deep2Params.materialCode = iterator.materialCode;
            }
          }
          this.getmaterialLevelDeep2local();
        }
      }
      this.isShow = true;
      if (this.currentDeepEchart == 7) {
        for (const iterator of this.materialRatioList7.materialRatioList7) {
          if (
            iterator.supplierName == this.deepParams.name &&
            Number(iterator.ratio) * 100 == this.deepParams.data
          ) {
            this.deepParams.supplierCode = iterator.supplierCode;
          }
        }
        const tempObj = {
          divisionIds: this.queryParams.divisionId.join(),
          baseIds: this.queryParams.baseId.join(),
          materialDataType: this.queryParams.notes,
          materialLevel:
            this.deepParams.name == "A级物料"
              ? 1
              : this.deepParams.name == "B级物料"
              ? 2
              : this.deepParams.name == "C级物料"
              ? 3
              : this.deepParams.name == "D级物料"
              ? 4
              : "",
          materialTypeCode:
            this.deepParams.name == "主材"
              ? 1
              : this.deepParams.name == "辅材"
              ? 2
              : "",
          supplierCode: this.deepParams.supplierCode,
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        }
        console.log('======================>')
        this.getinspectionJumpMaterial(tempObj).then((res) =>
          this.queryParams.dataType == 1
            ? this.selfcontextmenu(res, 2, 3, true)
            : this.selfcontextmenu(res, "echartDeep2", 7.1)
        );
      } else if (this.currentDeepEchart == 8) {
        for (const iterator of this.materialRatioList8.materialRatioList8) {
          if (
            iterator.materialTypeName == this.deepParams.name &&
            Number(iterator.ratio) * 100 == this.deepParams.data
          ) {
            this.deepParams.materialCode = iterator.materialType;
          } else if (
            iterator.materialLevelName == this.deepParams.name &&
            Number(iterator.ratio) * 100 == this.deepParams.data
          ) {
            this.deepParams.materialCode = iterator.materialLevel;
          } else if (
            iterator.supplierName == this.deepParams.name &&
            Number(iterator.ratio) * 100 == this.deepParams.data
          ) {
            this.deepParams.supplierCode = iterator.supplierCode;
          }
        }
        console.log(
          this.materialRatioList8.materialRatioList8,
          this.deepParams.supplierCode,
          "第八个图标传统"
        );
        this.getinspectionMaterialMrbRatioDeep(
          {
            divisionIdList: this.queryParams.divisionId,
            baseIdList: this.queryParams.baseId,
            materialDataType: this.queryParams.notes,
            isPenetrate: 1,
            penetrateCode:
              this.queryParams.dataType == 1
                ? this.deepParams.supplierCode
                : this.deepParams.materialCode,
            // dataType: this.queryParams.dataType,
            sort: this.queryParams.sort,
            ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
          },
          this.queryParams.dataType
        ).then((res) =>
          this.queryParams.dataType == 1
            ? this.selfcontextmenu(res, 2, 3, true)
            : this.selfcontextmenu(res, "echartDeep2", 8.1)
        );
      } else if (this.currentDeepEchart == 9) {
        if (this.queryParams.dataType == 1) {
          let supplierCode = this.filterData(
            this.deepParams.name,
            this.materialRatioList9.materialRatioList9,
            "supplierCode"
          );
          this.getmaterialInsFinishRateByExtraDeep(
            {
              baseIdList: this.queryParams.baseId,
              materialDataType: this.queryParams.notes,
              supplierCode,
              sort: this.queryParams.sort,
              ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
            },
            this.queryParams.dataType
          ).then((res) => this.selfcontextmenu(res, 2, 3, true));
        } else if (this.queryParams.dataType == 0) {
          console.log(this.deepParams, this.materialRatioList9, "materialCode");
          let materialCode =
            this.queryParams.notes == 0
              ? this.filterData(
                  this.deepParams.name,
                  this.materialRatioList9.materialRatioList9,
                  "materialLevel"
                )
              : this.filterData(
                  this.deepParams.name,
                  this.materialRatioList9.materialRatioList9,
                  "materialType"
                );
          this.deepParams.materialCode = materialCode;
          this.getmaterialInsFinishRateByExtraDeep(
            {
              baseIdList: this.queryParams.baseId,
              divisionIdList: this.queryParams.divisionId,
              materialDataType: this.queryParams.notes,
              isPenetrate: 1,
              penetrateCode: materialCode,
              sort: this.queryParams.sort,
              ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
            },
            this.queryParams.dataType
          ).then((res) => this.selfcontextmenu(res, "echartDeep2", 9.1));
        }
      }
    },
    getinspectionJumpMaterialSupplierlocal() {
      // this.isShow = true
      this.getinspectionJumpMaterialSupplier({
        divisionIds: this.queryParams.divisionId.join(),
        baseIds: this.queryParams.baseId.join(),
        materialDataType: this.queryParams.notes,
        materialLevel:
          this.deepParams.name == "A级物料"
            ? 1
            : this.deepParams.name == "B级物料"
            ? 2
            : this.deepParams.name == "C级物料"
            ? 3
            : this.deepParams.name == "D级物料"
            ? 4
            : "",
        materialTypeCode:
          this.deepParams.name == "主材"
            ? 1
            : this.deepParams.name == "辅材"
            ? 2
            : "",
        materialCode: this.deep2Params.materialCode,
        dataType: this.queryParams.dataType,
        sort: this.queryParams.sort,
      });
    },
    getinspectionMaterialMrbRatioDeep2local() {
      // this.isShow = true
      this.getinspectionMaterialMrbRatioDeep2({
        divisionIdList: this.queryParams.divisionId,
        baseIdList: this.queryParams.baseId,
        materialDataType: this.queryParams.notes,
        isPenetrate: 1,
        penetrateCode:
          this.queryParams.dataType == 1
            ? this.deepParams.supplierCode
            : this.deepParams.materialCode,
        isPenetrate2: 1,
        penetrateCode2: this.deep2Params.materialCode,
        // dataType: this.queryParams.dataType,
        sort: this.queryParams.sort,
        ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
      });
    },
    getmaterialLevelDeep2local() {
      this.getmaterialLevelDeep2({
        baseIdList: this.queryParams.baseId,
        divisionIdList: this.queryParams.divisionId,
        materialDataType: this.queryParams.notes,
        isPenetrate: 1,
        penetrateCode: this.deepParams.materialCode,
        isPenetrate2: 1,
        penetrateCode2: this.deep2Params.materialCode,
        sort: this.queryParams.sort,
        ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
      });
    },
    filterData(selfVal, dataList, getKey) {
      for (const iterator of dataList) {
        for (const key in iterator) {
          if (Object.hasOwnProperty.call(iterator, key)) {
            if (selfVal == iterator[key]) {
              return iterator[getKey];
            }
          }
        }
      }
    },
    godetail() {
      console.log(
        this.deepParams,
        this.deep2Params,
        this.currentDeepEchart,
        this.materialRatioList7.materialRatioList7,
        this.queryParams
      );
      if (this.currentDeepEchart == 7) {
        if (this.queryParams.dataType == 0) {
          if (this.queryParams.notes == 0) {
            console.log("跳转第7个");
            let materialLevel = this.filterData(
              this.deepParams.name,
              this.materialRatioList7.materialRatioList7,
              "materialLevel"
            );
            let url = `${window.location.origin}/ny-iqc/inspect/incoming?sheetStatus=5&result=1&materialLevel=${materialLevel}&inspectionEndTime=${this.materialRatioList7.inspectionEndTime}&inspectionStartTime=${this.materialRatioList7.inspectionStartTime}`;
            console.log(url);
            window.open(url);
          } else if (this.queryParams.notes == 1) {
            let materialType = this.filterData(
              this.deepParams.name,
              this.materialRatioList7.materialRatioList7,
              "materialType"
            );
            let url = `${window.location.origin}/ny-iqc/inspect/incoming?sheetStatus=5&result=1&materialKind=${materialType}&inspectionEndTime=${this.materialRatioList7.inspectionEndTime}&inspectionStartTime=${this.materialRatioList7.inspectionStartTime}`;
            window.open(url);
          }
        } else if (this.queryParams.dataType == 1) {
          let supplierCode = this.filterData(
            this.deepParams.name,
            this.materialRatioList7.materialRatioList7,
            "supplierCode"
          );
          let url = `${window.location.origin}/ny-iqc/inspect/incoming?sheetStatus=5&result=1&supplierCode=${supplierCode}&inspectionEndTime=${this.materialRatioList7.inspectionEndTime}&inspectionStartTime=${this.materialRatioList7.inspectionStartTime}`;
          window.open(url);
        }
      } else if (this.currentDeepEchart == 8) {
        if (this.queryParams.dataType == 0) {
          if (this.queryParams.notes == 0) {
            console.log("跳转第8个");
            let materialLevel = this.filterData(
              this.deepParams.name,
              this.materialRatioList8.materialRatioList8,
              "materialLevel"
            );
            let url = `${
              window.location.origin
            }/ny-iqc/inspect/incoming?sheetStatus=4&materialLevel=${materialLevel}&inspectionEndTime=${
              this.materialRatioList8.inspectionEndTime.split(" ")[0]
            }&inspectionStartTime=${
              this.materialRatioList8.inspectionStartTime.split(" ")[0]
            }`;
            console.log(url);
            window.open(url);
          } else if (this.queryParams.notes == 1) {
            let materialType = this.filterData(
              this.deepParams.name,
              this.materialRatioList8.materialRatioList8,
              "materialType"
            );
            let url = `${
              window.location.origin
            }/ny-iqc/inspect/incoming?sheetStatus=4&materialKind=${materialType}&inspectionEndTime=${
              this.materialRatioList8.inspectionEndTime.split(" ")[0]
            }&inspectionStartTime=${
              this.materialRatioList8.inspectionStartTime.split(" ")[0]
            }`;
            window.open(url);
          }
        } else if (this.queryParams.dataType == 1) {
          let supplierCode = this.filterData(
            this.deepParams.name,
            this.materialRatioList8.materialRatioList8,
            "supplierCode"
          );
          let url = `${
            window.location.origin
          }/ny-iqc/inspect/incoming?sheetStatus=4&supplierCode=${supplierCode}&inspectionEndTime=${
            this.materialRatioList8.inspectionEndTime.split(" ")[0]
          }&inspectionStartTime=${
            this.materialRatioList8.inspectionStartTime.split(" ")[0]
          }`;
          window.open(url);
        }
      } else if (this.currentDeepEchart == 9) {
        if (this.queryParams.dataType == 0) {
          if (this.queryParams.notes == 0) {
            console.log("跳转第8个");
            let materialLevel = this.filterData(
              this.deepParams.name,
              this.materialRatioList9.materialRatioList9,
              "materialLevel"
            );
            let url = `${
              window.location.origin
            }/ny-iqc/inspect/incoming?sheetStatus=3,14,15,9,8,7,5,4,2,10,1&materialLevel=${materialLevel}&inspectionEndTime=${
              this.materialRatioList9.inspectionEndTime.split(" ")[0]
            }&inspectionStartTime=${
              this.materialRatioList9.inspectionStartTime.split(" ")[0]
            }`;
            console.log(url);
            window.open(url);
          } else if (this.queryParams.notes == 1) {
            let materialType = this.filterData(
              this.deepParams.name,
              this.materialRatioList9.materialRatioList9,
              "materialType"
            );
            let url = `${
              window.location.origin
            }/ny-iqc/inspect/incoming?sheetStatus=3,14,15,9,8,7,5,4,2,10,1&materialKind=${materialType}&inspectionEndTime=${
              this.materialRatioList9.inspectionEndTime.split(" ")[0]
            }&inspectionStartTime=${
              this.materialRatioList9.inspectionStartTime.split(" ")[0]
            }`;
            window.open(url);
          }
        } else if (this.queryParams.dataType == 1) {
          let supplierCode = this.filterData(
            this.deepParams.name,
            this.materialRatioList9.materialRatioList9,
            "supplierCode"
          );
          let url = `${
            window.location.origin
          }/ny-iqc/inspect/incoming?sheetStatus=3,14,15,9,8,7,5,4,2,10,1&supplierCode=${supplierCode}&inspectionEndTime=${
            this.materialRatioList9.inspectionEndTime.split(" ")[0]
          }&inspectionStartTime=${
            this.materialRatioList9.inspectionStartTime.split(" ")[0]
          }`;
          window.open(url);
        }
      }
    },
    // deepData() {
    //   this.showDa = true;
    //   this.setData
    // },
    async listALLFactory(n) {
      if (n == 1) {
        await this.changedivisionId();
      }
      const { divisionId, baseId } = this.queryParams;
      await listALLFactory({
        divisionId,
        baseId: baseId ? baseId : undefined,
      }).then((res) => {
        if (res.data) {
          const plantCodes = res.data.map((i) => i.plantCode);
          this.queryParams.plantCode = plantCodes;
          this.initChart(plantCodes);
        } else {
          this.echart1?.dispose();
          this.echart2?.dispose();
          this.echart3?.dispose();
          this.echart4?.dispose();
          this.echart5?.dispose();
          this.echart6?.dispose();
        }
      });
    },
    domInit() {
      // const self = this;
      // /** 监听文本框内容高度*/
      // const observer = new ResizeObserver((entries) => {
      //   entries.forEach((entry) => {
      //     const cr = entry.contentRect;
      //     self.bodyWidth = cr.width;
      //     self.bodyHeight = cr.height;
      //   });
      // });
      // observer.observe(this.$refs.body);
    },
    handleExit() {
      window.opener = null;
      window.open("", "_self");
      window.close();
      this.$router.go(-1);
    },
    async initPage(fresh) {
      //事业部门
      if (!fresh) {
        await divisionAndBaseList().then((res) => {
          this.deptList = res;
          this.queryParams.divisionId = [res[0].divisionId];
          this.factoryList = [...res[0].baseList];
          this.queryParams.baseId = [this.factoryList[0].baseId];
        });
      }
      //厂区
      // await listBaseAPI(this.queryParams.divisionId).then((res) => {
      //   this.factoryList = res.data;
      //   const { baseId, baseName } = res.data[0] || {};
      //   this.queryParams.baseId = baseId;
      // });

      // this.initChartData()
      console.log(this.queryParams, "===========================>");
      const { endTime, startTime } = this;
      this.getinspectionOKRatio({
        ...this.date,
        sort: this.queryParams.sort,
        endTime,
        startTime,
      });
      this.getinspectionDivisionBaseRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionBaseMaterialRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          baseIds: this.queryParams.baseId.join(),
          materialDataType: this.queryParams.notes,
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      ).then((res) => this.selfcontextmenu(res, "", 7));
      //
      this.getinspectionDivisionMrbRatio({
        ...this.date,
        sort: this.queryParams.sort,
        endTime,
        startTime,
      });
      this.getinspectionDivisionBaseMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionMaterialMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      ).then((res) => this.selfcontextmenu(res, "", 8));
      //
      this.getinspectionFinishRateByExtra({
        ...this.date,
        sort: this.queryParams.sort,
        endTime,
        startTime,
        // divisionId: this.queryParams.divisionId,
      });
      this.getbaseInsFinishRateByExtra(
        {
          divisionId: this.queryParams.divisionId,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      );
      this.getsupplierInsFinishRateByExtra(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          endTime,
          startTime,
        },
        this.queryParams.dataType
      ).then((res) => this.selfcontextmenu(res, "", 9));
      // .then((res) => this.selfcontextmenu(res,'',9));
    },
    filterId(temp, name) {
      let arr = JSON.parse(JSON.stringify(temp));
      for (var i = 0; i < arr.length - 1; i++) {
        for (var j = i + 1; j < arr.length; j++) {
          if (arr[i][name] == arr[j][name]) {
            arr.splice(j, 1);
            //因为数组长度减小1，所以直接 j++ 会漏掉一个元素，所以要 j--
            j--;
          }
        }
      }
      return arr;
    },
    changedivision(divisions) {
      // 节流
      if (this.timer) {
        clearTimeout(this.timer);
      }
      this.timer = setTimeout(() => {

      let temp = [];
      this.queryParams.baseId = [];
      this.queryParams.notes = 0;
      for (const i of divisions) {
        for (const j of this.deptList) {
          if (i == j.divisionId) {
            temp = temp.concat(j.baseList);
          }
        }
      }
      let tempBaseList = this.filterId(temp, "baseId");

      // for (let i = 0; i < temp.length; i++) {
      //   if(!tempBaseList.length)tempBaseList.push(temp[i])
      //     for (let j = 0; j < tempBaseList.length; j++) {
      //         if (temp[i] == tempBaseList[j]) {
      //             // if(tempBaseList.length > 1){
      //             //   tempBaseList.splice(i, 1)
      //             //   j--
      //             // }
      //         }else{
      //           tempBaseList.push(temp[i])
      //         }
      //     }
      //   }
      console.log(tempBaseList);
      this.factoryList = tempBaseList;
      this.queryParams.baseId = [this.factoryList[0].baseId];
      this.getinspectionDivisionBaseRatio(
        {
          divisionIds: divisions.join(),
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionDivisionBaseMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          // dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getbaseInsFinishRateByExtra(
        {
          divisionId: this.queryParams.divisionId,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );

      }, 500);
},
    changeBase() {
      console.log(this.queryParams, "===========================>");
      // 节流
      if (this.timer1) {
        clearTimeout(this.timer1);
      }
      this.timer1 = setTimeout(() => {
        this.getinspectionBaseMaterialRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          baseIds: this.queryParams.baseId.join(),
          materialDataType: this.queryParams.notes,
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionMaterialMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          // dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getsupplierInsFinishRateByExtra(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );

      }, 500);
     },
    changeABC(val) {
      this.getinspectionBaseMaterialRatio(
        {
          divisionIds: this.queryParams.divisionId.join(),
          baseIds: this.queryParams.baseId.join(),
          materialDataType: val,
          dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getinspectionMaterialMrbRatio(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          // dataType: this.queryParams.dataType,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
      this.getsupplierInsFinishRateByExtra(
        {
          divisionIdList: this.queryParams.divisionId,
          baseIdList: this.queryParams.baseId,
          materialDataType: this.queryParams.notes,
          sort: this.queryParams.sort,
          ...this.date,
          startTime: this.startTime,
          endTime: this.endTime,
        },
        this.queryParams.dataType
      );
    },

    // initChartData(){
    //   inspectionOKRatio({}).then((res) => {

    //   })
    // },
    formatCE_NCR(e) {
      if (e) {
        let obj = this.dict.type.NYIQC_NCR_DECISION.find((item) => {
          return item.value === e;
        });
        if (obj) {
          return obj.label;
        } else {
          return "";
        }
      } else {
        return "";
      }
    },
  },
};
</script>

<style scoped src="./index.scss" lang="scss"></style>
